﻿
Partial Class store_UCCreatespace
    Inherits System.Web.UI.UserControl


    Public Sub Display(p As CProduct, isAll As Boolean)
        If isAll Then divDesc.Style("height") = "120px"

        lnkName.Text = HttpUtility.HtmlEncode(p.ProductName) '.Replace("~", "<br>").Replace("(", "<br>(") 'AndPrice
        lnkName.NavigateUrl = CSitemap.External_CreateSpace(p)

        If p.HasImage Then
            lnkThumb.NavigateUrl = CSitemap.External_CreateSpace(p)
            lnkThumb.Visible = True
            lnkThumb.ImageUrl = CSitemap.ProductImage(p)
            If isAll Then lnkThumb.ImageUrl = CSitemap.ProductTiny(p)
        Else
            divBorder.Visible = False
        End If

        'Preview feature
        Dim id As Integer = p.ProductCSBookIdOrParent
        If id = 4103035 Then id = 3971864 'Identical books in different sizes
        If id = 4207199 Then id = 4101124 'D&H (small)
        If id = 4199816 Then id = 4100936 'AGHS (small)
        lnkPreview.NavigateUrl = CSitemap.Sermons(id, 0, 0)
        Dim matching As CProductList = CProduct.Cache.GetByCSBookId(id)
        If matching.Manuals.Count > 0 Then
            lnkPreview.NavigateUrl = CSitemap.Decide(matching.Manuals(0))
        ElseIf matching.ConferenceSets.Count = 1 Then
            With matching.ConferenceSets(0)
                If .Children.Manuals.Count = 1 Then
                    lnkPreview.NavigateUrl = CSitemap.Decide(matching.ConferenceSets(0).Children.Manuals(0))
                End If
            End With
        End If

        lnkOrderNow.NavigateUrl = CSitemap.External_CreateSpace(p)
        If Not String.IsNullOrEmpty(p.ProductAmazonId) Then
            lnkAmazon.NavigateUrl = CSitemap.External_Amazon(p.ProductAmazonId, p.ProductName)
        Else
            lnkAmazon.Visible = False
        End If

        litDescription.Text = Server.HtmlEncode(p.ProductDescription).Replace(vbCrLf, "<br>")
        lblKeywords.Text = Server.HtmlEncode(p.ProductKeywords).Replace(vbCrLf, "<br>")
        If isAll Then lblKeywords.Font.Size = New FontUnit("8px")

        lnkName.ToolTip = p.ProductName
        lnkThumb.ToolTip = p.ProductName

        If Not IsNothing(p.BelongsTo) Then
            If litDescription.Text.Trim.Length = 0 Then
                litDescription.Text = Server.HtmlEncode(p.BelongsTo.ProductDescription).Replace(vbCrLf, "<br>")
            End If
        End If

        If litDescription.Text.Length < 100 Then
            divDesc.Style("height") = "auto"
        End If
    End Sub

End Class
